<template>
  <a-card :bordered='false'>
    <search ref='search' :config='searchConfig' @search='search' @getHeight='getHeight' />
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-90'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config="tableToolbar"
        :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >

        <template #toolbar_buttons>
          <div class="table-operator" style="border-top: 5px">
            <a-button @click="downExportXls('baseLog_service')">导出</a-button>
          </div>
        </template>

        <template #userType='{row }'>
          {{ row.userType == 1 ? '内部用户' : '外部用户' }}
        </template>
        <template #createTime="{ row }">
          {{ row.createTime*1000 | moment }}
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>

          </vxe-pager>
        </template>
      </vxe-grid>
    </div>


    <form-add-edit ref='formAdd' @ok='modelFormOk'></form-add-edit>
  </a-card>
</template>

<script>
import FormAddEdit from '@comp/view/base-crud/form/FormAddEdit'
import { PageListMixin } from '@/mixins/PageListMixin'
import Vue from 'vue'
import { filterObj } from '@/utils/util'
import search from '@comp/view/base-crud/search/Search'

export default {
  name: 'product-list',
  mixins: [PageListMixin],
  components: {
    FormAddEdit,
    search
  },
  data() {
    return {
      description: '接口配置',
      searchConfig: [
        {
          type: 'input',
          name: 'interfaceId',
          placeholder: '接口ID'
        },
        {
          type: 'date',
          name: 'createTime',
          placeholder: '创建日期'
        },
        {
          type: 'input',
          name: 'interfaceType',
          placeholder: '接口类型'
        },
        {
          type: 'input',
          name: 'interfaceTitle',
          placeholder: '接口标题'
        },
        {
          type: 'input',
          name: 'userName',
          placeholder: '登录账号'
        }
      ],
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      //列定义
      defColumns: [

        {
          title: '接口类型',
          field: 'interfaceType',
          width: 120,
          minWidth: 120,
          fixed: 'left'
        },
        {
          title: '接口ID',
          minWidth: 120,
          field: 'interfaceId'
        },
        {
          title: '接口标题',
          minWidth: 120,
          field: 'interfaceTitle'
        },
        {
          title: '接口入参',
          minWidth: 120,
          field: 'requestJson'
        },
        {
          title: '业务文本消息',
          minWidth: 120,
          field: 'responseJson'
        },
        {
          title: '用时(毫秒)',
          minWidth: 120,
          field: 'reqTime'
        },
        {
          title: '创建时间',
          minWidth: 120,
          field: 'createTime',
          slots: {
            default: 'createTime'
          }
        },
        {
          title: '登录账号',
          field: 'userName',
          width: 120,
          minWidth: 120,
        },
        {
          title: '角色',
          minWidth: 120,
          field: 'roleNames'
        },
        {
          title: '用户类型',
          minWidth: 120,
          field: 'userType',
          slots: { default: 'userType' }
        },
      ],
      url: {
        list: window._CONFIG['domianMqURL'] + '/logApi/findPageList',

      }
    }
  },
  created() {
    this.initColumns()
  },
  methods: {
    getQueryParams() {
      //高级查询器
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters)

      param.field = this.getQueryField()
      param.current = this.ipagination.current
      param.size = this.ipagination.pageSize
      delete param.birthdayRange //范围参数不传递后台
      return filterObj(param)
    },
    //列设置更改事件
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ':colsettings'
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
      this.settingColumns = checkedValues
      const cols = this.defColumns.filter(item => {
        if (item.key == 'rowIndex' || item.field == 'action') {
          return true
        }
        if (this.settingColumns.includes(item.field)) {
          return true
        }
        return false
      })
      this.columns = cols
    },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

      var key = this.$route.name + ':colsettings'
      let colSettings = Vue.ls.get(key)
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = []
        this.defColumns.forEach(function(item, i, array) {
          allSettingColumns.push(item.field)
        })
        this.settingColumns = allSettingColumns
        this.columns = this.defColumns
      } else {
        this.settingColumns = colSettings
        const cols = this.defColumns.filter(item => {
          if (item.key == 'rowIndex' || item.field == 'action') {
            return true
          }
          if (colSettings.includes(item.field)) {
            return true
          }
          return false
        })
        this.columns = cols
      }
    },
    handlePaginationChange(value) {
      this.ipagination.pageSize = value
      this.ipagination.current = 1
      this.loadData()
    },
    paginationCurrent(value) {
      if (value == 1) {
        if (this.ipagination.current > 1) {
          this.ipagination.current--
          this.loadData()
        } else {
          this.$message.info('已经是第一页了哦！')
        }
      } else {
        this.ipagination.current++
        this.loadData()
      }
    }


  }

}
</script>
<style lang='less' scoped>
@import '~@assets/less/common.less';

.pagination {
  text-align: right;
  width: 100%;
  padding: 8px 0;
  background-color: #FFFFFF;

  .div-box {
    height: 24px;
    line-height: 22px;
    font-size: 13px;
    display: inline-block;
    border: 1px solid #d9d9d9;
    padding: 0 8px;
    border-radius: 5px;
    margin-right: 10px;
  }

  .div-box:hover {
    background-color: #00A0E9;
    color: #FFFFFF;
    border-color: transparent;
  }
}
</style>